<?php
namespace app\admin\model;
use think\Model;

class Evaluate extends Model
{

    public function master()
    {
        return $this->hasOne('Place', 'id', 'place_id')->field('designation');
    }

    public function user()
    {
        return $this->hasOne('Cuser', 'id', 'user_id')->field('telphone');
    }

    public function getEvaluationTimeTurnAttr($value,$data)
    {
        return date('Y-m-d H:i:s', $data['evaluation_time']);
    }

    public function getEvaluate()
    {
        $id = input('id');
         $sql = "SELECT p.designation,eva.content,eva.user_id,eva.id,eva.grade,c.nickname,cu.telphone FROM gx_place p,gx_evaluate eva,gx_cuser_info c, gx_cuser cu WHERE p.id = eva.place_id AND c.uid = eva.user_id AND cu.id = c.uid AND p.id ={$id} ORDER BY eva.id";

         $data = Db::table('evaluate')->query($sql);
//        $where = ['p.id'=>['in',$id]];
//        $data = Db::name('evaluate')
//        ->alias('eva')
//        ->join('gx_place p','p.id = eva.place_id')
//         ->join('gx_cuser_info c','c.uid = eva.user_id')
//         ->join('gx_cuser cu','cu.id = c.uid')
//        ->where($where)
//        ->paginate('',false,page_param());
        return $data;
    }

}